/*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.

See Copyright-FEBio-Studio.txt for details.

Copyright (c) 2020 University of Utah, The Trustees of Columbia University in 
the City of New York, and others.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/

#pragma once
#include "Animation.h"
#ifdef WIN32
#include <vfw.h>

//-----------------------------------------------------------------------------
//! Base class for creating animation
class CAVIAnimation : public CAnimation
{
public:
	CAVIAnimation();

public:
	int Create(const char* szAVIFile, int cx, int cy, float fps = 10.f);
	int Write(QImage& im);
	void Close();
	bool IsValid() { return (m_pfile != NULL); }
	int Frames() override { return m_nsample; }

protected:
	PAVIFILE	m_pfile;	// the avifile pointer
	PAVISTREAM	m_pavi;		// the avistream pointer
	PAVISTREAM	m_pavicmp;	// the compressed avi stream
	AVISTREAMINFO* m_pai;

	int			m_nsample;	// index of next sample to write

	int			m_cx;		// width of animation rectangle
	int			m_cy;		// height of animation rectangle

	unsigned char*	m_buf;		// pixel buffer
	int				m_bufSize;	// buffer size
	int				m_bufLine;	// bytes per line (must be multiple of 4!)

	AVISTREAMINFO		m_ai;
	BITMAPINFOHEADER	m_bmi;
};
#endif
